//
//  NSString+cate.m
//  ShiWu
//
//  Created by  on 2022/7/28.
//

#import "NSString+cate.h"

@implementation NSString (cate)
+ (NSString *)URLEncodedString:(NSString *)string {
    NSString *encodedString = (NSString *)
    CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
                                                              (CFStringRef)string,
                                                              NULL,
                                                              (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                              kCFStringEncodingUTF8));
    
    return encodedString;
}
- (CGSize)sizeWithFont:(UIFont *)font inWidth:(CGFloat )width
{
    CGSize size = CGSizeMake(width, MAXFLOAT);
    CGRect rect = [self boundingRectWithSize:size
                                     options:NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
                                  attributes:@{NSFontAttributeName:font}
                                     context:nil];
    return CGSizeMake(ceil(rect.size.width), ceil(rect.size.height));
}
/**
 *@pragma 判断是否数字和字母混合
 */
- (BOOL)isNumberOrAlphabet
{
    NSString *match = @"^([a-zA-Z0-9]|[a-z]|[A-Z]|[0-9])+$";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
    return [predicate evaluateWithObject:self];
}
@end
